<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>

  function ascii(str) {
    var strAscii = new Array();//用于接收ASCII码
    for(var i = 0 ; i < str.length ; i++ ){
      strAscii[i] = str.charCodeAt(i);
    }
    return strAscii
  }
  function swap(arr1,arr2){
    var len=arr1.length>arr2.length?arr2.length:arr1.length;
    let flag=false;
    for(var i=0;i<len;i++){
      if(arr2[i]>arr1[i]){
        flag=true
        break;
      }
    }
    return flag
  }
  var str='add,ddf,sfsaf,g,gds'
  var arr=str.split(',')
  for ( var i=0;i<arr.length-1;i++){
    for (var j=0;j<arr.length-1-i;j++) {
      if (swap(ascii(arr[j]),ascii(arr[j + 1] ))) {
        var temp = arr[i];
        arr[j] = arr[j + 1];
        arr[j + 1] = temp;
      }
    }
  }
  console.log(arr);


</script>
</body>
</html>
